package com.fenghongzhang.lib_jetpack.room.raw

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class MysqliteHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {

    companion object {
        private const val DATABASE_NAME = "mydatabase.db"
        private const val DATABASE_VERSION = 1
    }

    //运行能一遍
    override fun onCreate(db: SQLiteDatabase) {
        // 创建表
       db.beginTransaction()
        val CREATE_TABLE_USERS = "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)"
        db.execSQL(CREATE_TABLE_USERS)
        val CREATE_TABLE_USER1S = "CREATE TABLE users (id INTEGER PRIMARY1 KEY AUTOINCREMENT, name TEXT, age INTEGER)"
        db.execSQL(CREATE_TABLE_USERS)
        db.endTransaction()

    }

    //每次版本变化会支持
    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        // 升级数据库时的操作
        db.execSQL("DROP TABLE IF EXISTS users")
        onCreate(db)
    }
}